<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>首页</title>
  <link rel="stylesheet" href="./bootstrap/bootstrap.min.css" />
  <link rel="stylesheet" href="./bootstrap/bootstrap-icons.css" />
  <link rel="stylesheet" href="./css/common.css" />
  <link rel="stylesheet" href="./css/index.css" />
</head>

<body class="application application-offset">
  <div class="container-fluid container-application">
    <div class="sidenav show" id="sidenav-main">
      <!-- Sidenav header -->
      <div class="sidenav-header d-flex align-items-center">
        <a class="navbar-brand" href="./index.html">
          <span class="logo">·ITCAST·</span>
        </a>
      </div>
      <!-- User mini profile -->
      <div class="sidenav-user d-flex flex-column align-items-center justify-content-between text-center">
        <!-- Avatar -->
        <div>
          <a href="#" class="avatar rounded-circle avatar-xl">
            <img alt="Image placeholder" src="https://yanxuan-item.nosdn.127.net/8b27deb1670c53e67c42ca3e1ed6fd12.jpg"
              class="" />
          </a>
          <div class="mt-5">
            <h5 class="mb-0 text-white">黑马前端</h5>
            <span class="d-block text-sm text-white opacity-8 mb-3">数据可视化</span>
            <a href="javascript:;" class="btn btn-sm btn-white btn-icon rounded-pill shadow hover-translate-y-n3">
              <span class="btn-inner--text">学前端来黑马</span>
            </a>
          </div>
        </div>
      </div>
      <!-- Application nav -->
      <div class="nav-application clearfix">
        <a href="./index.html" class="btn btn-square text-sm active">
          <span class="btn-inner--icon d-block"><i class="bi bi-house bi-2x"></i></span>
          <span class="btn-inner--icon d-block pt-2">首页</span>
        </a>
        <a href="./student.html" class="btn btn-square text-sm">
          <span class="btn-inner--icon d-block"><i class="bi bi-people bi-2x"></i></span>
          <span class="btn-inner--icon d-block pt-2">学生</span>
        </a>
        <a href="javascript:;" class="btn btn-square text-sm">
          <span class="btn-inner--icon d-block"><i class="bi bi-columns bi-2x"></i></span>
          <span class="btn-inner--icon d-block pt-2">排版</span>
        </a>
        <a href="javascript:;" class="btn btn-square text-sm">
          <span class="btn-inner--icon d-block"><i class="bi bi-files bi-2x"></i></span>
          <span class="btn-inner--icon d-block pt-2">资料</span>
        </a>
        <a href="javascript:;" class="btn btn-square text-sm">
          <span class="btn-inner--icon d-block"><i class="bi bi-receipt bi-2x"></i></span>
          <span class="btn-inner--icon d-block pt-2">就业</span>
        </a>
        <a href="javascript:;" class="btn btn-square text-sm">
          <span class="btn-inner--icon d-block"><i class="bi bi-gear bi-2x"></i></span>
          <span class="btn-inner--icon d-block pt-2">设置</span>
        </a>
      </div>
      <!-- Misc area -->
      <div class="card bg-gradient-warning">
        <div class="card-body">
          <h5 class="text-white">哈喽, 朋友!</h5>
          <p class="text-white mb-4">为什么不现在开始学习前端，创造一些令人惊叹的东西呢？</p>
          <a href="http://itcast.cn" class="btn btn-sm btn-block btn-white rounded-pill" target="_blank">Get started</a>
        </div>
      </div>
    </div>
    <div class="main-content position-relative">
      <nav class="navbar navbar-main navbar-expand-lg navbar-dark navbar-border" id="navbar-main">
        <div class="container-fluid">
          <!-- Navbar nav -->
          <div class="collapse navbar-collapse navbar-collapse-fade" id="navbar-main-collapse">
            <ul class="navbar-nav align-items-lg-center">
              <!-- Home  -->
              <li class="nav-item">
                <a class="nav-link pl-lg-0" href="./index.html"> 首页 </a>
              </li>
              <li class="nav-item">
                <a class="nav-link pl-lg-0" href="./index.html"> 传智教育 </a>
              </li>
              <li class="nav-item">
                <a class="nav-link pl-lg-0" href="./index.html"> 黑马程序员 </a>
              </li>
              <li class="nav-item">
                <a class="nav-link pl-lg-0" href="./index.html"> 文档 </a>
              </li>
            </ul>
            <!-- Right menu -->
            <ul class="navbar-nav ml-lg-auto align-items-center d-none d-lg-flex">
              <li class="nav-item dropdown dropdown-animate">
                <a class="nav-link pr-lg-0" href=".dropdown-menu" role="button" data-toggle="dropdown"
                  aria-haspopup="true" aria-expanded="false">
                  <div class="media media-pill align-items-center">
                    <span class="avatar rounded-circle">
                      <img alt="Image placeholder"
                        src="https://yanxuan-item.nosdn.127.net/8b27deb1670c53e67c42ca3e1ed6fd12.jpg" />
                    </span>
                    <div class="ml-2 d-none d-lg-block">
                      <span id="username" class="mb-0 text-sm font-weight-bold">Admin</span>
                    </div>
                  </div>
                </a>
              </li>
              <li class="nav-item">
                <a class="nav-link pl-lg-0" id="logout" href="javascript:;"> 退出 </a>
              </li>
            </ul>
          </div>
        </div>
      </nav>
      <div class="page-content">
        <!-- Page Title -->
        <div class="page-title">
          <div class="row justify-content-between align-items-center">
            <div class="col-md-6 mb-3 mb-md-0">
              <h5 class="h3 font-weight-400 mb-0 text-white">Dashboard</h5>
              <span class="text-sm text-white opacity-8">北京顺义前端108期</span>
            </div>
          </div>
        </div>
        <!-- charts -->
        <div class="row">
          <div class="col-xl-3 col-md-6">
            <div class="card card-stats">
              <div class="card-body">
                <div class="row">
                  <div class="col">
                    <h6 class="text-muted mb-1">就业薪资</h6>
                    <span name="salary" class="h3 font-weight-bold mb-0 ">12500</span>
                  </div>
                  <div class="col-auto">
                    <i class="bi bi-coin"></i>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="col-xl-3 col-md-6">
            <div class="card card-stats">
              <div class="card-body">
                <div class="row">
                  <div class="col">
                    <h6 class="text-muted mb-1">班级人数</h6>
                    <span name="student_count" class="h3 font-weight-bold mb-0 ">44</span>
                  </div>
                  <div class="col-auto">
                    <i class="bi bi-people"></i>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="col-xl-3 col-md-6">
            <div class="card card-stats">
              <div class="card-body">
                <div class="row">
                  <div class="col">
                    <h6 class="text-muted mb-1">平均年龄</h6>
                    <span name="age" class="h3 font-weight-bold mb-0 ">24.40</span>
                  </div>
                  <div class="col-auto">
                    <i class="bi bi-calendar2-week"></i>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="col-xl-3 col-md-6">
            <div class="card card-stats">
              <!-- Card body -->
              <div class="card-body">
                <div class="row">
                  <div class="col">
                    <h6 class="text-muted mb-1">小组个数</h6>
                    <span name="group_count" class="h3 font-weight-bold mb-0 ">8</span>
                  </div>
                  <div class="col-auto">
                    <i class="bi bi-collection"></i>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col col-xl-8">
            <div class="card" id="line" style="height: 400px;"></div>
          </div>
          <div class="col col-xl-4">
            <div class="card" id="salary" style="height: 400px;"></div>
          </div>
          <div class="col col-xl-12">
            <div class="card" style="height: 400px;">
              <div class="card-header">
                <div class="d-flex justify-content-between align-items-center">
                  <h6 class="mb-0">班级每组薪资</h6>
                  <div id="btns">
                    <button type="button" class="btn btn-xs btn-blue">1</button>
                    <button type="button" class="btn btn-xs ">2</button>
                    <button type="button" class="btn btn-xs ">3</button>
                    <button type="button" class="btn btn-xs ">4</button>
                    <button type="button" class="btn btn-xs ">5</button>
                    <button type="button" class="btn btn-xs ">6</button>
                    <button type="button" class="btn btn-xs ">7</button>
                    <button type="button" class="btn btn-xs ">8</button>
                  </div>
                </div>
              </div>
              <div class="card-body p-0" id="lines"></div>
            </div>
          </div>
          <div class="col col-xl-4">
            <div class="card" id="gender" style="height: 500px;"></div>
          </div>
          <div class="col col-xl-8">
            <div class="card" id="map" style="height: 500px;"></div>
          </div>
        </div>
        <!-- footer -->
        <div class="footer pt-5 pb-4 footer-light" id="footer-main">
          <div class="row text-center text-sm-left align-items-sm-center">
            <div class="col-sm-6">
              <p class="text-sm mb-0">© 2022 <a href="https://itcast.cn" class="h6 text-sm" target="_blank">前端学科</a>.
                All rights reserved.</p>
            </div>
            <div class="col-sm-6 mb-md-0">
              <ul class="nav justify-content-center justify-content-md-end">
                <li class="nav-item">
                  <a class="nav-link" href="#">Support</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="#">Terms</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link pr-0" href="#">Privacy</a>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <script src="./bootstrap/bootstrap.min.js"></script>
  <script src="./lib/axios.js"></script>
  <script src="./lib/echarts.min.js"></script>
  <script src="./lib/message.js"></script>
  <script src="./js/common.js"></script>
  <script src="./lib/china.js"></script>
  <script>
    // ---------------------------发送请求获取所需要的数据----------------------
    axios.get('/dashboard').then(({ data: res }) => {
      console.log(res);
      let { data: { groupData, overview, provinceData, salaryData, year } } = res;
      // 设置概览区的四个数据: 
      for (let key in overview) {
        document.querySelector(`[name=${key}]`).innerHTML = overview[key];
      }
      // 获取到接口数据后 再调用图表函数 将数据传递到图标函数中
      linestart(year);
      classSalaryChart(salaryData);
      classSalaryChartzx(salaryData);
      lineChart(groupData);
      myMap(provinceData);
    });
    // ---------------------------折线图-------------------------------------
    function linestart(data) {
      let myChart = echarts.init(document.querySelector('#line'));
      let option = {
        title: {
          text: '2022全学科薪资走势',
          top: 15,
          let: 10,
          textStyle: {
            fontSize: 16
          }
        },
        tooltip: {
          trigger: 'axis'
        },
        grid: {
          top: '20%'
        },
        xAxis: {
          type: 'category',
          data: data.map(item => item.month),
          axisLabel: {
            color: '#999'
          },
          splitLine: {
            lineStyle: {
              color: '#ccc',
              type: 'dashed'
            }
          }
        },
        yAxis: {
          type: 'value'
        },
        splitLine: {
          lineStyle: {
            type: 'dashed'
          }
        },
        color: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [{
            offset: 0, color: '#499FEE' // 0% 处的颜色
          }, {
            offset: 1, color: '#5D75F0' // 100% 处的颜色
          }],
          global: false // 缺省为 false
        },
        series: [
          {
            data: data.map(item => item.salary),
            type: 'line',
            smooth: true, //平滑曲线
            // 线条样式 
            lineStyle: {
              width: 6,
            },
            symbolSize: 10,
            areaStyle: {
              color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [{
                  offset: 0, color: '#499FEE' // 0% 处的颜色
                }, {
                  offset: 0.8, color: 'rgba(255,255,255,0.2)' // 0% 处的颜色
                }, {
                  offset: 1, color: 'rgba(255,255,255,0)' // 100% 处的颜色
                }],
                global: false // 缺省为 false
              }
            }
          }
        ]
      };
      myChart.setOption(option);
    }
    // linestart();

    // ----------------------------饼图--------------------------------
    function classSalaryChart(data) {
      let myChart = echarts.init(document.querySelector('#salary'));
      let option = {
        title: {
          text: '班级薪资分布',
          top: 15,
          left: 10,
          textStyle: {
            fontSize: 16
          }
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          bottom: '6%',
          left: 'center'
        },
        color: ['#FDA224', '#5097FF', '#3ABCFA', '#34D39A'],
        series: [
          {
            name: '班级薪资分布',
            type: 'pie',
            radius: ['50%', '64%'],
            // avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: false,
            },
            // emphasis: {
            //   label: {
            //     show: true,
            //     fontSize: '40',
            //     fontWeight: 'bold'
            //   }
            // },
            labelLine: {
              show: false
            },
            data: data.map(item => {
              return {
                value: item.g_count + item.b_count,
                name: item.label
              }
            })
          }
        ]
      };
      myChart.setOption(option);
    };
    // classSalaryChart();

    // ---------------------------柱状图------------------------------
    function lineChart(data) {
      // console.log(data);
      let myChart = echarts.init(document.querySelector('#lines'));
      let option = {
        // 鼠标移入提示
        tooltip: {},
        // 网格设置 向四周拉伸一下图表
        grid: {
          top: 30,
          right: 30,
          left: 70,
          bottom: 50,
        },
        // x轴上的设置
        xAxis: {
          type: 'category',
          // data: data[1].map(item => item.name),
          data: data[1].map(item => item.name),
          // x轴文字设置

          axisLabel: {
            color: '#999'
          },
          // x轴线设置
          axisLine: {
            // 轴线样式设置
            lineStyle: {
              color: '#ccc',
              type: 'dashed'
            }
          },
        },
        yAxis: {
          type: 'value',
          // y轴分割线配置
          splitLine: {
            lineStyle: {
              type: 'dashed'
            }
          }
        },
        color: [{
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [{
            offset: 0, color: '#34D39A' // 0% 处的颜色
          }, {
            offset: 1, color: 'rgba(52,211,154,0.2)' // 100% 处的颜色
          }],
          global: false // 缺省为 false
        }, {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [{
            offset: 0, color: '#499FEE' // 0% 处的颜色
          }, {
            offset: 1, color: 'rgba(73,159,238,0.2)' // 100% 处的颜色
          }],
          global: false // 缺省为 false
        }],
        series: [

          {
            data: data[1].map(item => item.hope_salary),
            type: 'bar',
            name: '期望薪资',
          },
          {
            // data: data[1].map(item => item.salary),
            data: data[1].map(item => item.salary),
            type: 'bar',
            name: '实际薪资'
          }
        ]
      };
      myChart.setOption(option);
      // ====================补充柱状图上面的  标签点击事件===============
      // document.querySelector('#btns').addEventListener('click', function (e) {
      //   if (e.target.tagName === 'BUTTON') {
      //     // 获取到对应的组号
      //     let num = e.target.innerHTML
      //     console.log(num);
      //     document.querySelector('#btns .btn-blue').classList.remove('btn-blue');
      //     e.target.classList.add('btn-blue');
      //     option.xAxis.data = data[num].map(item => item.name);
      //     option.series[0].data = data[num].map(item => item.hope_salary);
      //     option.series[1].data = data[num].map(item => item.salary);
      //     myChart.setOption(option);
      //   }
      // })
      document.querySelector('#btns').addEventListener('click', function (e) {
        if (e.target.tagName === 'BUTTON') {
          let i = e.target.innerHTML;
          document.querySelector('#btns .btn-blue').classList.remove('btn-blue');
          e.target.classList.add('btn-blue');
          option.xAxis.data = data[i].map(item => item.name);
          option.series[0].data = data[i].map(item => item.hope_salary);
          option.series[1].data = data[i].map(item => item.salary);
          myChart.setOption(option);
        }
      })
    }
    // lineChart();
    // --------------------------左下饼图------------------------------- 
    function classSalaryChartzx(data) {
      let myChart = echarts.init(document.querySelector('#gender'));
      let option = {
        // 标题配置
        title: [
          {
            text: '男女薪资分布',
            left: 10, // 10 表示10px
            top: 10,
            textStyle: {
              fontSize: 16
            }
          },
          {
            text: '男生',
            left: '45%', // 10 表示10px
            top: '45%',
            textStyle: {
              fontSize: 12
            }
          },
          {
            text: '女生',
            left: '45%', // 10 表示10px
            top: '85%',
            textStyle: {
              fontSize: 12
            }
          }
        ],
        // 鼠标移入的提示
        tooltip: {
          trigger: 'item'
        },
        // 颜色的设置
        color: ['#FDA224', '#5097FF', '#3ABCFA', '#34D39A'],
        // 系列数据
        series: [
          {
            name: '男生薪资分布', // 这个名字会显示在 提示框中
            type: 'pie', // 表示饼图
            center: ['50%', '30%'], // 圆心点坐标
            radius: ['20%', '30%'], // 内外圈的半径
            data: data.map(item => {
              return {
                value: item.b_count,
                name: item.label
              }
            })
          },
          {
            name: '女生薪资分布', // 这个名字会显示在 提示框中
            type: 'pie', // 表示饼图
            center: ['50%', '70%'], // 圆心点坐标
            radius: ['20%', '30%'], // 内外圈的半径
            data: data.map(item => {
              return {
                value: item.g_count,
                name: item.label
              }
            })
          }
        ]
      };
      myChart.setOption(option);
    };
    // classSalaryChartzx();
    // ---------------------------地图-----------------------------------
    function myMap(data) {
      console.log(data);
      const mapData = [
        { name: '南海诸岛', value: 0 },
        { name: '北京', value: 0 },
        { name: '天津', value: 0 },
        { name: '上海', value: 0 },
        { name: '重庆', value: 0 },
        { name: '河北', value: 0 },
        { name: '河南', value: 0 },
        { name: '云南', value: 0 },
        { name: '辽宁', value: 0 },
        { name: '黑龙江', value: 0 },
        { name: '湖南', value: 0 },
        { name: '安徽', value: 0 },
        { name: '山东', value: 0 },
        { name: '新疆', value: 0 },
        { name: '江苏', value: 0 },
        { name: '浙江', value: 0 },
        { name: '江西', value: 0 },
        { name: '湖北', value: 0 },
        { name: '广西', value: 0 },
        { name: '甘肃', value: 0 },
        { name: '山西', value: 0 },
        { name: '内蒙古', value: 0 },
        { name: '陕西', value: 0 },
        { name: '吉林', value: 0 },
        { name: '福建', value: 0 },
        { name: '贵州', value: 0 },
        { name: '广东', value: 0 },
        { name: '青海', value: 0 },
        { name: '西藏', value: 0 },
        { name: '四川', value: 0 },
        { name: '宁夏', value: 0 },
        { name: '海南', value: 0 },
        { name: '台湾', value: 0 },
        { name: '香港', value: 0 },
        { name: '澳门', value: 0 }
      ]
      // 首先循环遍历 此数组对象 最终目的为了更改value的值
      mapData.forEach(item => {
        // 然后在data数组里查找
        let res = data.find(v => {
          // 数据里是否包含 城市
          return v.name.includes(item.name)
        });
        if (res) {
          // 有则替换对应的value值
          item.value = res.value;
        }
      })
      let myChart = echarts.init(document.querySelector('#map'));
      let option = {
        tooltip: {
          formatter: '{b} : {c} 位学员',
          textStyle: {
            color: '#fff'
          },
          backgroundColor: 'rgba(0,0,0,0.5)',
          borderColor: 'transparent'

        },
        title: {
          text: '籍贯分布',
          top: 15,
          left: 10,
          textStyle: {
            fontSize: 16
          }
        },
        // 系列数据
        series: [{
          data: mapData,
          name: '籍贯分布',
          type: 'map',
          map: 'china',
          label: {
            show: true,
            fontSize: 10,
            color: 'rgba(0,0,0,0.7)'//字体颜色
          },
          itemStyle: {
            areaColor: '#E0FFFF', //省的颜色
            borderColor: 'rgba(0, 0, 0, 0.2)' //边框的颜色
          },
          // 高亮状态下 区域的样式
          emphasis: {
            itemStyle: {
              areaColor: '#34D39A',
              borderWidth: 0,
              shadowBlur: 20,
              shadowOffsetX: 0,
              shadowOffsetY: 0,
              shadowColor: 'rgba(0,0,0,0.5)'
            },
          },
        }],
        // 视觉映射组件
        visualMap: {
          type: 'continuous',
          max: 10,
          min: 0,
          text: [10, 0],
          left: 40,
          bottom: 20,
          inRange: {
            color: ['#fff', '#0075F0']
          }
        },

      };
      myChart.setOption(option);
    };
    // myMap();
  </script>
</body>

</html>